package com.vhall.component.framework.core.loader;

import lombok.Data;

import java.util.List;
import java.util.regex.Pattern;

@Data
public class ExtensionProperties {

    private String application;

    private List<String> plugins;

    /**
     * 匹配当前应用名是否跟应用文件匹配
     *
     * @param extensions
     * @return
     */
    public void replacePlugin(List<CustomerExtension> extensions) {
        Pattern regex = createPattern();
        extensions.forEach(extension -> {
            String url = extension.getResources();
            if (regex.matcher(url).find()) {
                extension.replaceClasses(plugins);
            }
        });
    }

    /**
     * 生成匹配应用名的正则表达式
     *
     * @return
     */
    private Pattern createPattern() {
        return Pattern.compile(".*/" + application + "(/|-).*");
    }

}
